<%@ page language="java" contentType="text/html; charset=UTF-8" %> 
<%@page import="weaver.general.GCONST"%>
<%@page import="java.io.File"%>
<%@page import="weaver.email.WeavermailComInfo"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="weaver.email.service.MailManagerService"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="net.sf.json.JSONArray"%>
<%@page import="weaver.conn.RecordSet"%>
<%@page import="weaver.file.FileUpload"%>
<%@page import="weaver.hrm.User"%>
<%@page import="weaver.mobile.plugin.ecology.service.HrmResourceService"%>
<%@page import="weaver.general.Util"%>
<%@page import="weaver.systeminfo.SystemEnv"%>
<jsp:useBean id="mrs" class="weaver.email.service.MailResourceService" />
<jsp:useBean id="mms" class="weaver.email.service.MailManagerService" scope="page" />
<jsp:useBean id="mrfs" class="weaver.email.service.MailResourceFileService" />
<%
//获取邮件显示数据
String userid = Util.null2String(request.getParameter("userid"));
HrmResourceService hrs = new HrmResourceService();
User user = hrs.getUserById(Util.getIntValue(userid));
request.setCharacterEncoding("UTF-8");
FileUpload fu=new FileUpload(request);
int mailid = Util.getIntValue(fu.getParameter("mailid"),-1);
int type = Util.getIntValue(fu.getParameter("type"),-1);

// 读取邮件，并加载到缓存中
String mailContent = "";
if(type==1){
	mrs.setId(mailid+"");
	mrs.selectMailResource();
	if(mrs.next()){
		mailContent = mrs.getContent();
		if(mrs.getHashtmlimage().equals("1")){
			mrfs.selectMailResourceFileInfos(mailid+"","0");
			while(mrfs.next()){
				int imgId = mrfs.getId();
				String thecontentid = mrfs.getFilecontentid();
				String oldsrc = "cid:" + thecontentid ;
				String newsrc = "http://"+Util.getRequestHost(request)+"/weaver/weaver.email.FileDownloadLocation?fileid="+imgId;
				mailContent = Util.StringReplaceOnce(mailContent , oldsrc , newsrc ) ;
			}
		}
		mailContent = Util.replace(mailContent, "==br==", "\n", 0);
	}
}else if(type==2){
//获取邮件编辑数据
	int flag = Util.getIntValue(fu.getParameter("flag"));
	if(flag!=-1){
			if(flag ==1){//回复
				mms.getReplayMailInfo(mailid+"",user);
			}else if(flag==2){//回复全部
				mms.getReplayAllMailInfo(mailid+"",user);
			}else if(flag==3){//转发
				mms.getForwardMailInfo(mailid+"",user);
			}else if(flag==4||flag == 5){//草稿
				mms.getDraftMailInfo(mailid+"",user);
			}
			
	     	if(flag==4){
	     			String fengeinput="<br><font style=color:red>"+SystemEnv.getHtmlLabelName(81409,user.getLanguage())+"</font><span id=EmailNew_fengeinput></span><br>";
	     			mailContent=mms.getContent().replace(fengeinput, "");
	     	}else{
	     		mailContent = mms.getContent();
	     	}
			mailContent = mms.getContent();
	}
}

%>
<%=mailContent %>